<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>8.2</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .imgs {
            width: 520px;
            margin: 100px auto;
            border: 1px solid green;
        }

        .imgs li {
            list-style-type: none;
            float: left;
            padding-left: 5px;
        }

        .imgs img {
            width: 125px;
        }

        html,
        body {
            height: 100%;
        }

        body {
            background: url(./img/1.jpg)  no-repeat;
            background-size: cover;
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <ul class="imgs">
        <li><img src="./img/1.jpg" alt=""></li>
        <li><img src="./img/2.jpg" alt=""></li>
        <li><img src="./img/3.jpg" alt=""></li>
        <li><img src="./img/4.jpg" alt=""></li>
    </ul>
    <script>
        var bgs = document.querySelector('.imgs').querySelectorAll('img');
        console.log(bgs);
        for (let index = 0; index < bgs.length; index++) {
           bgs[index].onclick=function(){
               document.body.style.backgroundImage='url(' +this.src+ ')';
           }
            
        }
    </script>

</body>

</html>